package com.designpatternspart2.structuraldesignpatterns.compositepattern;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Lance
 */
public class Composite implements Component
{

    private List<Component> components = new ArrayList<Component>();

    @Override
    public void sayHello()
    {
        for (Component component : getComponents())
        {
            component.sayHello();
        }
    }

    @Override
    public void sayGoodbye()
    {
        for (Component component : getComponents())
        {
            component.sayGoodbye();
        }
    }

    public void add(Component component)
    {
        getComponents().add(component);
    }

    public void remove(Component component)
    {
        getComponents().remove(component);
    }

    public List<Component> getComponents()
    {
        return components;
    }

    public Component getComponent(int index)
    {
        return getComponents().get(index);
    }

    public void setComponents(List<Component> components)
    {
        this.components = components;
    }
}
